<?php include("src/addUser_cs.php");
@session_start();
$_SESSION['varMenu'] = 'Usuarios'; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Agregar Usuario</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script src="../js/jquery.js" type="text/javascript"></script>
<script>J = jQuery.noConflict()</script>


</head>

<body class="style" onload="MM_preloadImages('images/menu3.png','images/menu2.png','images/assignr.png','images/new_taskr.png','images/mailr.png','images/edit_2r.png','images/client_3r.png','images/deleter.png','images/backr.png','images/noter (1).png')">

<div id="container">
  <?php include('header.php');?>
  <div id="mainContent">  
    <?php include('menuTop.php');?>
    <div id="bg">
	 <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
     <input type="hidden" name="add" id="add" value="1"/>
      <table width="100%" border="0" cellspacing="0" cellpadding="4">
        
        <tr>
          <td><H1>Agregar Usuario</H1></td>
        </tr>
        <tr>
          <td align="center"><table width="80%" border="0" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
            <tr>
              <td colspan="2" align="center" valign="top" bgcolor="#400000">&nbsp;</td>
            </tr>
            <tr>
              <td width="75%" align="center" valign="top"><table width="80%" border="0" cellspacing="0" cellpadding="4">
                  <tr>
                    <td width="30%" align="left"><strong>
                      <h2>NOMBRE:</h2>
                    </strong></td>
                    <td width="70%" align="left"><input type="text" name="name" id="name" size="40" /></td>
                  </tr>
                </table>
                 <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><h2>DEPENDENCIA:</h2></td>
                      <td width="70%" align="left"><input type="text" name="dependencia" id="dependencia" size="40" /></td>
                    </tr>
                </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><h2>EMAIL:</h2></td>
                      <td width="70%" align="left"><input type="text" name="email" id="email" size="40" /></td>
                    </tr>
                </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><strong>
                        <h2>TELÉFONO:</h2>
                      </strong></td>
                      <td width="70%" align="left"><input type="text" name="phone" id="phone" size="40" /></td>
                    </tr>
                  </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><strong>
                        <h2>USUARIO:</h2>
                      </strong></td>
                      <td width="70%" align="left"><input type="text" name="login" id="login" size="40" /></td>
                    </tr>
                  </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><strong>
                        <h2>CONTRASEÑA:</h2>
                      </strong></td>
                      <td width="70%" align="left"><input type="password" name="password" id="password" size="40" /></td>
                    </tr>
                  </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><strong>
                        <h2>CONFIRMAR CONTRASEÑA:</h2>
                      </strong></td>
                      <td width="70%" align="left"><input type="password" name="confirmar" id="confirmar" size="40" /></td>
                    </tr>
                  </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left"><strong>
                        <h2>TIPO DE USUARIO:</h2>
                      </strong></td>
                      <td width="70%" align="left"> <select name="type" id="type" >
                                <option value="seleccione" selected="selected" disabled="disabled" >Seleccione...</option>
                               <?php 
							   $i=0;
							   while($i<count($user_types))
							   {
							   ?>
							    	<option value="<?php echo $user_types[$i];?>"><?php echo $user_types[$i];?></option>
                                <?php 
							   $i++;
							   }
							    ?>								
                              </select></td>
                    </tr>
                  </table>
                <table width="80%" border="0" cellspacing="0" cellpadding="4">
                    <tr>
                      <td width="30%" align="left" valign="top"><strong>
                        <h2>FOTO:</h2>
                      </strong></td>
                      <td width="70%" align="left" valign="top"><input type="file" name="archivo[]"/></td>
                    </tr>
					<tr>
					<td colspan="3" align="center"><input type="button" value="Guardar"  onclick="javascript: return checkLogin();"/>
					<input type="reset" value="Limpiar"/>	
					<input onClick="javascript:window.history.back();" type="button" name="Submit" value="Cancelar" /></td> </tr>
                </table></td>
             
            </tr>
            <tr>
              <td colspan="2" align="center" valign="top" bgcolor="#400000"><br /></td>
            </tr>
          </table>
          <br />            <br /></td>
        </tr>
      </table>
	  </form>
    </div>
    <br />
    <br />
    <!-- end #mainContent -->
  </div>
  <?php include('footer.php');?>
<!-- end #container --></div>

</body>
</html>
<script language="javascript" type="text/javascript">

	function checkLogin()
	 {
	 	var login  = document.getElementById("login").value;
	 	
		J.ajax({
		type: "POST",
		url: "userDuplicatecheck.php",
		data: 'login='+login,
		success: function(msg)
		{						
			if(msg==0)
			{	
				validate();				
			}
			else
			{
				alert('El nombre de usuario no se encuentra disponible.');			
				document.getElementById("login").value = ""				
			}			
		}
		});		
	 }
	 
	function validate()
	{ 
	  var msg    = '';
	 
	  var name   = document.getElementById("name").value;
	  var login  = document.getElementById("login").value;
	  var p1     = document.getElementById("password").value;
      var p2     = document.getElementById("confirmar").value;     
	  var type     = document.getElementById("type").value;     
	
	  if(name == '') 
	  msg='Por favor ingrese un nombre. \n';
	 
	 if(login == '') 
	  msg= msg+'Por favor ingrese un nombre de usuario.\n';	 
	  
	  if(type == 'seleccione') 
	  msg= msg+'Seleccione un tipo de usuario.\n';	 
	 	
	  var espacios = false;
	  var cont = 0;
		 
	  while (!espacios && (cont < p1.length))
	  {
	    if (p1.charAt(cont) == " ")
		  espacios = true;
		  cont++;
	  }
	
	  if (espacios)
	  {
	  	 msg= msg+'La contraseña no puede contener espacions. \n';	 
	  }
	 
	  if (p1.length == 0 || p2.length == 0) 
	  {
	    msg= msg+'Por favor ingrese una contraseña. \n';	 
      }
		
	  if (p1 != p2)  
	  {
	     msg= msg+'Las contraseñas no coinciden. \n';	 
	  } 	 		
	
	  if(msg=='')
	  {
	  	document.getElementById('form').submit();
		return true;
	  }
	  else
	  {
		alert(msg, 'ERROR');
	 	return false;
	  }
	
	}
</script>